// components/navbar/index.js
const App = getApp();

Component({
  options: {
    addGlobalClass: true,
  },
  /**
   * 组件的属性列表
   */
  properties: {
    pageName:{
      type:String,
      value:''
    },
    showNav:{
      type:Boolean,
      value:true
    },
    showHome: {
      type: Boolean,
      value: false
    },
    sale:{
      type:Boolean,
      value: false
    },
    toTop:{
      type:Number,
      value:0
    },
    defindShowHome:{
      type: Boolean,
      value: false
    },
    customUrl:{
       type:String,
       value:'',
       observer:function(newVal,oldVal){
          if(newVal){
            this.setData({
              newCustomUrl:newVal
            });
          }
       }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    headPic:'',
    newCustomUrl:''

  },
  lifetimes: {
    attached: function () {
      let employee = wx.getStorageSync('employee');
      this.setData({
        navH: App.globalData.navHeight,
        navTop:App.globalData.navTop,
        headPic:employee?employee.headPic:''
      })
     }
     
  },
  pageLifetimes:{
    show:function(){
      let page = getCurrentPages();
      let { showNav } = this.data;
     if (page.length == 1) {
         showNav = false 
       }
       this.setData({showNav});
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    //回退
    navBack () {
      this.triggerEvent('backEvent')
      if(this.data.newCustomUrl){
        wx.redirectTo({
          url:this.data.newCustomUrl
        });
        return;
      }
        wx.navigateBack({
          delta: 1
        })      
    },
    toSales() {
      wx.navigateTo({
        url: '/pages/sales/radar/radar'
      })
    },
    goBackIndex(){
      wx.switchTab({
        url: '/pages/index/index'
      })
    },
    goBackCustomPage(){
      wx.navigateTo({
        url: this.properties.newCustomUrl
      });
    }
  }
})